//
//  MyCommentCell.m
//  GolfFriend
//
//  Created by Vescky on 14-5-12.
//  Copyright (c) 2014年 vescky.org. All rights reserved.
//

#import "MyCommentCell.h"
#import "UIImageView+MJWebCache.h"
#import "DateUtility.h"
#import <QuartzCore/QuartzCore.h>

@interface MyCommentCell ()

@end

@implementation MyCommentCell

@synthesize cellData;

- (void)setCellDataInfo:(NSDictionary*)_dict {
    if (!_dict) {
        return;
    }
    cellData = _dict;
    NSString *imgLink = [cellData objectForKey:@"avatar"];
    if ([imgLink stringByMatching:@"qiniudn.com"]) {
        imgLink = GetQiniuResizeImageLink(imgLink, 100);
    }
    imgvAvatar.layer.cornerRadius = imgvAvatar.frame.size.width / 2.0;
    [imgvAvatar setImageURLStr:imgLink placeholder:Default_Avatar];
    
    labelUserName.text = [cellData objectForKey:@"nickName"];
    labelCommentContent.text = [cellData objectForKey:@"commentContent"];
    labelArticleContent.text = [cellData objectForKey:@"articleContent"];
//    labelArticleContent.layer.cornerRadius = 3.0;
    
    NSDate *dt = getDateFromString(@"yyyy-MM-dd HH:mm:ss", [cellData objectForKey:@"time"]);
    NSString *dtString = getStringFromDate(@"MM月dd日 HH:mm", dt);
    labelDateTime.text = dtString;
    
    CGRect contentFrame = labelCommentContent.frame;
    CGSize cSize = [[cellData objectForKey:@"commentContent"] sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(contentFrame.size.width,1000) lineBreakMode:0];
    contentFrame.size.height = cSize.height >= 20 ? cSize.height : 20;
    float increaseHeight = contentFrame.size.height - labelCommentContent.frame.size.height;
    labelCommentContent.frame = contentFrame;
    
    CGRect cellRect = self.frame;
    cellRect.size.height = cellRect.size.height + increaseHeight;
    self.frame = cellRect;
}

- (float)getCellHeightWithData:(NSDictionary*)_dict {
    [self setCellData:_dict];
    return self.frame.size.height;
}

@end
